package com.gjy.concurrency.clazz;

import org.junit.jupiter.api.Test;

import java.util.ArrayList;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.concurrent.ConcurrentSkipListSet;
import java.util.concurrent.ThreadLocalRandom;

/**
 * @author 宫静雨
 * @version 1.0
 * @since 2023-05-18 14:47:42
 */
public class ConSkipListMapTest {

    @Test
    public void test3() throws InterruptedException {
//        CopyOnWriteArrayList<Integer> list = new CopyOnWriteArrayList<>();
        ArrayList<Integer> list = new ArrayList<>();

        for (int i = 0; i < 10; i++) {
            list.add(i);
        }

        for (int i = 0; i < 10; i++) {
            new Thread(() -> {
                list.remove(0);
            }).start();
        }

        System.out.println(list);
    }

    @Test
    public void test2() {
        ConcurrentSkipListSet<Integer> set = new ConcurrentSkipListSet<>();

        for (int i = 0; i < 20; i++) {
            set.add(ThreadLocalRandom.current().nextInt(30));
        }

        System.out.println(set);
    }

    @Test
    public void test1() {
        ConcurrentSkipListMap<String, Integer> map = new ConcurrentSkipListMap<>();

        for (int i = 0; i < 20; i++) {
            map.put(String.valueOf(i), i);
        }

        System.out.println(map);
    }

}
